package com.liurui.demo.contoller;

import com.liurui.demo.mapper.DepartmentMapper;
import com.liurui.demo.mapper.EmployeeMapper;
import com.liurui.demo.pojo.Department;
import com.liurui.demo.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.Date;

@RestController
public class EmployeeController_test {

    @Autowired
    EmployeeMapper employeeMapper;
    @Autowired
    DepartmentMapper departmentMapper;
    // 获取所有员工信息
    @GetMapping("/getEmployees")
    public Collection<Employee> getEmployees(){
        return employeeMapper.getEmployees();
    }

    @GetMapping("/insert")
    public void insert(){
        Department department = departmentMapper.getDepartmentById(1);
        Employee employee = new Employee();
        employee.setLastName("kuangshen");
        employee.setEmail("qinjiang@qq.com");
        employee.setGender(1);
        employee.setDepartment(department);
        employee.setBirth(new Date());
        employeeMapper.insert(employee);
    }

    // 通过id获得员工信息
    @GetMapping("/get/{id}")
    public Employee get(@PathVariable("id") Integer id){
        return employeeMapper.getEmployeeById(id);
    }

    // 通过id删除员工
    @GetMapping("/delete/{id}")
    public void delete(@PathVariable("id") Integer id){
        employeeMapper.deleteEmployeeById(id);
    }

}
